package com.autohammal.monitor;

import com.autohammal.ITarget;
import com.autohammal.Monitor;
import com.autohammal.MonitorListener;
import com.autohammal.save.Saveable;

public abstract class AbstractMonitor implements Saveable, Monitor {

	protected ITarget target;
	protected String monitorName;
	protected MonitorListener monitorListener;

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.autohammal.monitor.Monitor#cancel()
	 */
	@Override
	public abstract void cancel();

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.autohammal.monitor.Monitor#start()
	 */
	@Override
	public abstract void start();

	protected abstract Runnable createSchedulerTask();
	
	
	public AbstractMonitor() {
		super();
	}

	public String getMonitorName() {
		return monitorName;
	}

	public void setMonitorName(String monitorName) {
		this.monitorName = monitorName;
	}

	public ITarget getTarget() {
		return target;
	}

	public void setTarget(ITarget target) {
		this.target = target;
	}

	public void addMonitorListener(MonitorListener monitorListener) {
		this.monitorListener = monitorListener;
	}

	@Override
	public String toString() {
		return getMonitorName();
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((monitorName == null) ? 0 : monitorName.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		SchedulerMonitor other = (SchedulerMonitor) obj;
		if (monitorName == null) {
			if (other.getMonitorName() != null)
				return false;
		} else if (!monitorName.equals(other.getMonitorName()))
			return false;
		return true;
	}

	@Override
	public String getSaveName() {
		return getMonitorName();
	}

}